package com.example.book_system.controller;

import com.example.book_system.common.Result;
import com.example.book_system.entity.Book;
import com.example.book_system.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 下面的 RestController 注解是 ResponseBody + Controller
 * 缺点是只能返回 JSON 对于本项目来说很适用
 * @author Administrator
 */
@RestController
@RequestMapping("/api/admin")
public class AdminController {
    private final AdminServiceImpl adminService;

    @Autowired
    public AdminController(AdminServiceImpl adminService){
        this.adminService = adminService;
    }

    @PostMapping("/addBook")
    public Result<String> addBook(@RequestBody Book book){
        return adminService.addBook(book);
    }

}
